package com.example.robertluozizhao.framecollectdemo.util.Exp

import android.graphics.Rect
import android.view.TouchDelegate
import android.view.View

/**
 *
 * <pre>
 *     author: luozz@anjiu-tech.com
 *     time  : 2022/4/2 10:39 上午
 *     desc  :
 * </pre>
 *
 **/
object ViewExp {

    fun View.clickExpend(listen: View.OnClickListener, expSize: Int = 20) {
        this.post {
            var expandExClick = Rect()
            this.getHitRect(expandExClick)

            this.setOnClickListener {
                listen.onClick(it)
            }

            expandExClick.top -= expSize
            expandExClick.left -= expSize
            expandExClick.right += expSize
            expandExClick.bottom += expSize

            val touchDelegate = TouchDelegate(expandExClick, this)

            this.parent?.let {
                (this.parent as View).touchDelegate = touchDelegate
            }

        }
    }

}